package com.el.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.el.bojo.Title;
import com.el.dao.BaseDao;
import com.el.dao.TitleDao;

public class TitleDaoImpl extends BaseDao implements TitleDao {

	@Override
	public List<Title> getAllTitle() {
		ResultSet rs = null;
		String sql = "select * from title ";
		rs = this.exxcuteQuery(sql);
		List<Title> list = new ArrayList<Title>();
		try {
			while (rs.next()) {
				Title title = new Title();
				title.setId(rs.getInt("id"));
				title.setTitle(rs.getString("title"));
				list.add(title);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			this.closeAll(connection, pstmt, rs);

		}
		return list;
	}

	public static void main(String[] args) {
		TitleDaoImpl titleDaoImpl = new TitleDaoImpl();
		List<Title> list = titleDaoImpl.getAllTitle();
		for (Title title : list) {
			System.out.println(title.getTitle());
		}
	}
}
